var loginpasswordOK = false;
var loginusernameOK = false;
var logincaptchaOK = false;

function verifylogin() {
	isloginPassword($("#password").val());
	isloginUsername($("#signInName").val());
	isloginCaptcha($("#loginCaptcha").val());
	return (loginpasswordOK && loginusernameOK && logincaptchaOK);
}

function isloginPassword(s) {
	var input = s.trim();
	var patrn = /^(\w){6,16}$/;
	if (input.length == 0) {
		checkloginpassword.innerHTML = "请输入密码";
		$("#checkloginpassword").show();
		loginpasswordOK = false;
	} else if (input.length < 6) {
		checkloginpassword.innerHTML = "密码过短，要求长度大于5";
		$("#checkloginpassword").show();
		loginpasswordOK = false;
	} else if (input.length > 16) {
		checkloginpassword.innerHTML = "密码过长，要求长度小于17";
		$("#checkloginpassword").show();
		loginpasswordOK = false;
	} else if (!patrn.exec(input)) {
		checkloginpassword.innerHTML = "密码不允许包含大小写字母、数字和下划线以外的字符";
		$("#checkloginpassword").show();
		loginpasswordOK = false;
	} else {
		$("#checkloginpassword").hide();
		loginpasswordOK = true;
	}
}

function isloginUsername(s) {
	var input = s.trim();
	var patrn = /^[a-zA-Z][a-zA-Z0-9_]{0,15}$/;
	var patrn2 = /^(\w){1,16}$/;
	if (input.length == 0) {
		checkloginusername.innerHTML = "请输入用户名";
		$("#checkloginusername").show();
		loginusernameOK = false;
	} else if (input.length > 16) {
		checkloginusername.innerHTML = "用户名过长，要求长度小于17";
		$("#checkloginusername").show();
		loginusernameOK = false;
	} else if (!patrn2.exec(input)) {
		checkloginusername.innerHTML = "用户名不允许包含大小写字母、数字和下划线以外的字符";
		$("#checkloginusername").show();
		loginusernameOK = false;
	} else if (!patrn.exec(input)) {
		checkloginusername.innerHTML = "用户名的第一个字符不能为下划线或数字";
		$("#checkloginusername").show();
		loginusernameOK = false;
	} else {
		$("#checkloginusername").hide();
		loginusernameOK = true;
	}
}

function isloginCaptcha(s) {
	var input = s.trim();
	var patrn = /^(\d){4,4}$/;
	if (input.length == 0) {
		checklogincaptcha.innerHTML = "请输入验证码";
		$("#checklogincaptcha").show();
		logincaptchaOK = false;
	} else if (!patrn.exec(input)) {
		checklogincaptcha.innerHTML = "验证码为4位数字";
		$("#checklogincaptcha").show();
		logincaptchaOK = false;
	} else {
		$("#checklogincaptcha").hide();
		logincaptchaOK = true;
	}
}